package HomeWork;

public class Work_1 {
    public static void main(String[] args) {
        Person[] person=new Person[3];
        person[0]=new Person("jackkokk",37,"student");
        person[1]=new Person("mack",99,"teacher");
        person[2]=new Person("packo",18,"cook");
        //按年龄冒泡排序
//        for(int i=0;i<person.length-1;i++){
//            for(int j=0;j< person.length-1-i;j++){
//                if(person[j].getAge()>person[j+1].getAge()){
//                    Person tem=person[j];
//                    person[j]=person[j+1];
//                    person[j+1]=tem;
//                }
//            }
//        }
        //按名字长度冒泡排序
        for(int i=0;i<person.length-1;i++){
            for(int j=0;j< person.length-1-i;j++){
                if(person[j].getName().length()>person[j+1].getName().length()){
                    Person tem=person[j];
                    person[j]=person[j+1];
                    person[j+1]=tem;
                }
            }
        }
        //打印数据
        for (int i = 0; i <person.length ; i++) {
            person[i].info();
        }


    }
}
class Person{
    private String name;
    private int age;
    private String job;

    public void info(){
        System.out.println(name+"\t"+age+"\t"+job);
    }

    public Person(String name, int age, String job) {
        this.name = name;
        this.age = age;
        this.job = job;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
